package com.itkaien.javaeebased.multipleSystem;

import java.util.concurrent.locks.Lock;

public class Work04 implements Runnable{



    private Integer number;

    private Integer orgin=0;

    private Lock lock;

    public Work04(Integer number, Lock lock) {
        this.number = number;
        this.lock = lock;
    }

    public Work04() {
    }


    @Override
    public void run(){

        while (true) {
            try {
            // 获取锁
            lock.lock();
            if (orgin>100) {
                break;
            }
                if (orgin% 2 == 1){
                    System.out.println(Thread.currentThread().getName() + ": 奇数" +orgin );
                }
                orgin++;
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                // 释放锁
                lock.unlock();
            }
        }


    }
}
